import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/Home.vue'

Vue.use(VueRouter)
// 获取原型上的push函数
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/goods',
    component: () => import('@/views/Goods.vue')
  },
  {
    path: '/user',
    component: () => import('@/views/User.vue')
  },
  {
    path: '/order',
    component: () => import('@/views/Order.vue')
  },
  {
    path: '/free',
    component: () => import('@/views/Free.vue')
  },
  {
    path: '/detalis',
    component: () => import('@/views/Details.vue')
  },
  {
    path: '*',
    component: () => import('@/components/Error.vue')
  },
]

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
})

export default router
